<?php


namespace app\adminapi\validate\member;


use app\common\model\member\MemberLevel;
use app\common\validate\BaseValidate;

/**
 * @projectName src
 */
class MemberLevelValidate extends BaseValidate
{
    protected $rule = [
        'id' => 'require|checkMemberLevel',
        'level_name' => 'require|unique:' . MemberLevel::class,
        'total_consume_money' => 'require|float|>=:0',
        'total_consume_time' => 'require|integer|>=:0',
    ];

    protected $message = [
        'id.require' => '参数缺失',
        'level_name.require' => '请填写会员等级名称',
        'level_name.unique' => '会员等级名称已存在',
        'total_consume_money.require' => '累计消费金额不能为空',
        'total_consume_money.float' => '累计消费金额必须为数字',
        'total_consume_money.>=:0' => '累计消费金额必须大于等于0',
        'total_consume_time.require' => '累计消费次数不能为空',
        'total_consume_time.number' => '累计消费次数必须为数字',
        'total_consume_time.>=:0' => '累计消费次数必须大于等于0',
    ];

    /**
     * @notes 添加场景
     * sceneAdd
     */
    public function sceneAdd()
    {
        return $this->remove('id', true);
    }

    /**
     * @notes 详情场景
     * sceneAdd
     */
    public function sceneDetail()
    {
        return $this->only(['id']);
    }

    /**
     * @notes 编辑场景
     * sceneAdd
     */
    public function sceneEdit()
    {
    }

    /**
     * @notes 删除场景
     * sceneAdd
     */
    public function sceneDelete()
    {
        return $this->only(['id']);
    }

    public function checkMemberLevel($value)
    {
        $memberLevel = MemberLevel::findOrEmpty($value);
        if ($memberLevel->isEmpty()) {
            return '会员等级不存在';
        }
        return true;
    }
}